// copyright jyz.2024


#include "UI/HUD/AuraHUD.h"
#include "Blueprint/UserWidget.h"
#include "UI/Widget/AuraUserWidget.h"
#include "UI/WidgetController/AttributeMenuWidgetController.h"
#include "UI/WidgetController/OverlayWidgetController.h"


void AAuraHUD::InitOverlay(APlayerController* PC, APlayerState* PS, UAbilitySystemComponent* ASC, UAttributeSet* AS)
{
	checkf(WBP_OverlayClass,TEXT("WBP Overlay Class uninitalized,pealse fill out BP_AuraHUD"));
	checkf(OverlayWidgetControllerClass,TEXT("Overlay Widget Controller Class uninitalized,pealse fill out BP_AuraHUD"))
	OverlayWidget = CreateWidget<UAuraUserWidget>(GetWorld(),WBP_OverlayClass);
	const FWidgetControllerParams WCParams(PC,PS,ASC,AS);
	if(!OverlayWidgetController)
	{
		OverlayWidgetController = NewObject<UOverlayWidgetController>(this,OverlayWidgetControllerClass);
		OverlayWidgetController->SetWidgetControllerParams(WCParams);
		//针对于客户端来说，得先绑定代理，在初始化代理广播（原因：网络同步已经将AS中的数据初始化了，AS的值不会在调用Change相关的代理）
		OverlayWidget->SetWidgetController(OverlayWidgetController);
		//初始化UI的值（广播代理的形式）
		OverlayWidgetController->BroadcastInitialValues();
	}

	OverlayWidget->AddToViewport();
	if(!AMWidgetCtrl)
	{
		AMWidgetCtrl = NewObject<UAttributeMenuWidgetController>(this,AMWidgetCtrlClass);
		AMWidgetCtrl->SetWidgetControllerParams(WCParams);
		//初始化UI的值（广播代理的形式）
		AMWidgetCtrl->BroadcastInitialValues();
	}
}
